package com.jzo2o.market.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.model.Result;
import com.jzo2o.market.model.dto.request.ActivityQueryForPageReqDTO;
import com.jzo2o.market.model.dto.request.ActivitySaveReqDTO;
import com.jzo2o.market.model.dto.response.ActivityInfoResDTO;
import com.jzo2o.market.service.IActivityService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@RestController("operationActivityController")
@RequestMapping("/operation/activity")
@Api(tags = "运营端 - 区域配置相关接口")
public class ActivityController {

    @Autowired
    private IActivityService activityService;



    //新增活动
    @PostMapping("/save")
    public Result save(@RequestBody ActivitySaveReqDTO activitySaveReqDTO) {
        activityService.saveOrUpdateById(activitySaveReqDTO);
        return Result.ok();
    }

    //分页查询活动
    //todo 每日一练
    @GetMapping("/page")
    public PageResult<ActivityInfoResDTO> page(ActivityQueryForPageReqDTO dto) {
        return activityService.findByPage(dto);
    }


    //查询优惠券活动详情
    @GetMapping("/{id}}")
    public Result<ActivityInfoResDTO> detail(Long id) {
        ActivityInfoResDTO activityInfoResDTO =activityService.findByActivityId(id);
        return Result.ok(activityInfoResDTO);
    }

    //撤销优惠券活动
    @PostMapping("/revoke/{id}")
    public Result revoke(@PathVariable Long id) {
        activityService.revoke(id);
        return Result.ok();
    }
}
